package org.mybatis.spring.boot.study.dataFlow.start_default;

import org.apache.ibatis.binding.MapperProxy;
import org.apache.ibatis.binding.MapperProxyFactory;
import org.mybatis.spring.boot.study.StudyConfig;
import org.mybatis.spring.boot.study.entity.TjsUser;
import org.mybatis.spring.boot.study.mapper.TjsUserMapper;
import org.mybatis.spring.mapper.MapperFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.Resource;

/**
 * @author nicky
 * @date 2021/9/1 上午11:47
 */
@SpringBootApplication
@AutoConfigurationPackage(basePackages = {"org.mybatis.spring.boot.study.mapper"})
public class DoTest implements CommandLineRunner {

    @Autowired
    TjsUserMapper tjsUserMapper;
    @Resource(name = "&tjsUserMapper")
    MapperFactoryBean mapperFactoryBean;

    /**
     * mapperFactoryBeanClass是代理的关键类
     * {@link MapperFactoryBean}
     * 生成代理的点
     * {@link MapperFactoryBean#getObject()}
     * {@link MapperProxyFactory#newInstance(org.apache.ibatis.binding.MapperProxy)}
     *  切面类{@link MapperProxy}
     *
     *
     *  SqlSessionTemplate
     *
     */
    public static void main(String[] args) {
        StudyConfig.thisDebugNames = "jsUserMapper";
        SpringApplication.run(DoTest.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        TjsUser tjsUser = tjsUserMapper.findByState("CA");
        System.out.println(tjsUser.toString());
    }
}
